package at.mri.dogwatch.client.pages.newvideo;

import at.mri.dogwatch.client.pages.widgets.videoeditor.VideoEditor;
import at.mri.dogwatch.shared.proxy.VideoProxy;

import com.gwtplatform.mvp.client.ViewImpl;
import com.google.gwt.core.client.GWT;
import com.google.gwt.editor.client.SimpleBeanEditorDriver;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class NewVideoView extends ViewImpl implements NewVideoPresenter.NewVideoView {

	private final Widget widget;
	
	@UiField VideoEditor videoEditor;

	public interface Binder extends UiBinder<Widget, NewVideoView> {
	}

	interface Driver extends SimpleBeanEditorDriver<VideoProxy, VideoEditor> {}
	
	Driver driver = GWT.create(Driver.class);
	
	@Inject
	public NewVideoView(final Binder binder) {
		widget = binder.createAndBindUi(this);
	}

	@Override
	public Widget asWidget() {
		return widget;
	}
	
	@Override
	public void edit(VideoProxy video){
		//initialize the driver with the top-level editor
		driver.initialize(videoEditor);
		//copy the data from the object into the UI
		driver.edit(video);
	}
	
	@Override
	public HasClickHandlers getPostButton(){
		return videoEditor.getPostButton();
	}
	
	/**
	 * updates the passed proxy-object
	 * with the values from the editor
	 */
	public void flush(){
		driver.flush();
	}

	@Override
	public void disable() {
		videoEditor.disable();
	}

	@Override
	public void enable() {
		videoEditor.enable();
	}
	
}
